package com.example.demo.designPattern.responsibility;

import org.omg.CORBA.Request;

import javax.xml.ws.Response;

/**
 * @Author: xiatian
 * @CreateTime: 2021/11/5 1:51 下午
 * @Description:
 */
public abstract class AbstractHandler {

    /**
     * 责任链中下一个对象
     */
    private AbstractHandler nextHandler;

    /**
     * 设置责任链的下一个对象
     *
     * @param nextHandler
     */
    public void setNextHandler(AbstractHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 具体参数拦截逻辑，给子类去实现
     */
    public void filter(Request request, Response response) {
        doFilter(request, response);
        if (nextHandler != null) {
            getNextHandler().filter(request, response);
        }
    }

    public AbstractHandler getNextHandler() {
        return nextHandler;
    }

    abstract void doFilter(Request request, Response response);

}
